#!/usr/bin/python
# -*- coding: utf8 -*-

#######################################################
## 多进程编程
# 1、进程池
#######################################################
import time
import os

def func():
    print('process {} start'.format(os.getpid()))
    time.sleep(2)
    print('process {} end'.format(os.getpid()))

if __name__ == '__main__':
    from multiprocessing import Process, cpu_count, Pool
    print('main process is {}'.format(os.getpid()))
    print('core number is {}'.format(cpu_count()))

    start_time = time.time()

    p = Pool(8)
    for i in range(14):
        p.apply_async(func)

    p.close()
    p.join()

    end_time = time.time()

    print('total time is {}'.format(str(end_time - start_time)))